<?php
namespace app\api\controller;
use app\common\controller\BaseApi;

/*AswS3  图片上传调用 */
class AswS3 extends  BaseApi
{
	 public function _initialize()
    {
    }
	/**
	 * 设备验证结果记录上传
	 * */
	function DeviceUpload(){
		$member_card_no=input("member_card_no");
		$pt_card_no=input("pt_card_no");
		$image_url=input("image_url");
		$type=input("type",0); //1私教打卡  2人脸平板
		$shop_id=input("shop_id");
		$secret=input("secret","");
		
		$order_pt_card_no=input("order_pt_card_no","");//
		$reservation_name=input("reservation_name","");//课程名称
		$cost_time=input("cost_time",0);//比对时间
		$reservation_status=input("reservation_status",0);//1上 课  2下课
		
		if(!in_array($type, [1,2])){
			return $this->api_ajax_error("","无效的type");
		}
		if(empty($member_card_no)||empty($image_url)||empty($type)||empty($shop_id)){
			 return $this->api_ajax_error("","参数错误");
		}
		
		if(empty(input("debug"))){
			if(md5($member_card_no.$shop_id)!=$secret){
				return $this->api_ajax_error("","无效的secret");
			}
		}
		$data=[
				"member_card_no"=>input("member_card_no"),
				"pt_card_no"=>input("pt_card_no",""),
				"image_url"=>input("image_url"),
				"shop_id"=>input("shop_id"),
				"member_name"=>"",
				"pt_name"=>"",
				"member_mobile"=>"",
				"pt_mobile"=>"",
				"remarks"=>"",
				"type"=>$type,
				"addr"=>input("addr",""),
				"ip"=>request()->ip(),
				"order_pt_card_no"=>$order_pt_card_no,
				"reservation_name"=>$reservation_name,
				"cost_time"=>$cost_time,
				"order_pt_mobile"=>"",
				"order_pt_name"=>"",
				"reservation_status"=>$reservation_status,
				"score_pt"=>input('score_pt'),
				"score_member"=>input('score_member'),
				"score_pt_member"=>input('score_pt_member'),
		];
		if($type==1){
			if(empty($pt_card_no)){
				return $this->api_ajax_error("","pt_card_no 为空");
			}
			//上课pt
			$pt=db("Interface")->field("name,mobile")->where("shop_id=$shop_id and owner_type=2 and card_no='$pt_card_no'")->find();
			if(empty($pt)){
				return $this->api_ajax_error("","无效的pt卡号");
			}else{
				//上课pt
				$data['pt_name']=$pt['name'];
				$data['pt_mobile']=$pt['mobile'];
				//预约pt
				if(!empty($order_pt_card_no)){
					$order_pt=db("Interface")->field("name,mobile")->where("shop_id=$shop_id and owner_type=2 and card_no='$order_pt_card_no'")->find();
					$data['order_pt_mobile']=$order_pt['mobile'];
					$data['order_pt_name']=$order_pt['name'];	
				}
			}
		}
		$member=db("Interface")->field("name,mobile")->where("shop_id=$shop_id and card_no='$member_card_no'")->find();
		if(empty($member)){
			return $this->api_ajax_error("","无效的会员卡号");
		}else{
			$data['member_name']=$member['name'];
			$data['member_mobile']=$member['mobile'];
		}
		db("FlatVarifyRecord")->insert($data);
		return $this->api_ajax_success();
	}
	////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
}
